const hanToast = require('../../utils/toast.js')
const request  = require('../../utils/request.js')
Page({
  data:{
    shopUser:'',
    shopPwd:''
  },
  bindUserInput:function(e){
    this.setData({shopUser:e.detail.value})
  },
  bindPwdInput:function(e){
    this.setData({ shopPwd: e.detail.value })
  },
  submit:function(){
    const { shopUser, shopPwd} = this.data;
    // 非空校验
    if (shopUser === '') return hanToast('账号不能为空')
    if (shopPwd === '') return hanToast('密码不能为空')

    request(['/store/login', 'POST', { shopUser, shopPwd}],res=>{
      // 登录成功
      if(res.code === 1){
        wx.setStorageSync('shopID', res.data.shopID)
        wx.setStorageSync('storeuid', res.data.storeuid)
        wx.switchTab({url: "/pages/index/index"})
        return 
      }
      // 登录失败给出提示
      hanToast(res.msg)
    }) 
  }
})